/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 * 注意：
 * 本软件为www.joolun.com开发研制，项目使用请保留此说明
 */
package com.ruoyi.mall.dubbo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.mall.api.RemoteGoodsSpuService;
import com.ruoyi.mall.api.entity.GoodsSpu;
import com.ruoyi.mall.mapper.GoodsSpuMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

/**
 * spu商品
 *
 * @author JL
 * @date 2019-08-12 16:25:10
 */
@Service
@DubboService
public class RemoteGoodsSpuServiceImpl extends ServiceImpl<GoodsSpuMapper, GoodsSpu> implements RemoteGoodsSpuService {


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    @Override
    public IPage<GoodsSpu> page1(IPage<GoodsSpu> page, GoodsSpu goodsSpu) {
        return baseMapper.selectPage1(page, goodsSpu);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save1(GoodsSpu goodsSpu) {
        return baseMapper.insert(goodsSpu) > 0 ? true : false;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById1(GoodsSpu goodsSpu) {
        return baseMapper.updateById(goodsSpu) > 0 ? true : false;
    }

    @Override
    public GoodsSpu getById1(String id) {
        return baseMapper.selectById1(id);
    }

    @Override
    public GoodsSpu getById2(String id) {
        return baseMapper.selectById2(id);
    }

    @Override
    public GoodsSpu getById(String id) {
        return super.getById(id);
    }

    @Override
    public boolean updateById(GoodsSpu entity) {
        return super.updateById(entity);
    }

    @Override
    public GoodsSpu getOneByIdAndShelfGeStock(String id, String shelf, Integer stock) {
        return super.getOne(Wrappers.<GoodsSpu>lambdaQuery()
            .eq(GoodsSpu::getId, id)
            .eq(GoodsSpu::getShelf, shelf)
            .ge(GoodsSpu::getStock, stock));
    }

    @Override
    public List<GoodsSpu> listByIds(Set<String> keySet) {
        return super.listByIds(keySet);
    }

    @Override
    public List<GoodsSpu> listByIdAndName(GoodsSpu goodsSpu) {
        return super.list(Wrappers.query(goodsSpu).lambda().select(GoodsSpu::getId, GoodsSpu::getName));
    }

    @Override
    public Long count(GoodsSpu goodsSpu) {
        return super.count(Wrappers.query(goodsSpu));
    }

    @Override
    public boolean updateInIds(GoodsSpu goodsSpu, List<?> toList) {
        return super.update(goodsSpu, Wrappers.<GoodsSpu>lambdaQuery().in(GoodsSpu::getId, toList));
    }

    @Override
    public boolean removeById(String id) {
        return super.removeById(id);
    }
}
